﻿using System.Collections.Generic;
using System.Drawing;
using CanvasControl.Model;

namespace CanvasControl.View
{
    public class BackgroundView : IBackgroundView
    {
        readonly Appearance background;
        readonly LineAppearance grid;

        public BackgroundView(Appearance background, LineAppearance grid)
        {
            this.background = background;
            this.grid = grid;
        }

        public void DrawBackground(DrawingContext dc, Rectangle area)
        {
            dc.Graphics.Clear(background.Color);
        }

        public void DrawBorder(DrawingContext dc, Rectangle area)
        {
            using (var pen = background.Border.CreatePen())
                dc.Graphics.DrawRectangle(pen, 0, 0, area.Width - pen.Width, area.Height - pen.Width);
        }

        public void DrawGrid(DrawingContext dc, IEnumerable<Line> lines)
        {
            using (var gridPen = grid.CreatePen())
            {
                foreach (var line in lines)
                    dc.Graphics.DrawLine(gridPen, line.start, line.end);
            }
        }
    }
}